/*     */ package blockbuster.components.shape;
/*     */ 
/*     */ import blockbuster.components.BedrockComponentBase;
/*     */ import blockbuster.emitter.BedrockEmitter;
/*     */ import blockbuster.emitter.BedrockParticle;
/*     */ import blockbuster.math.molang.MolangException;
/*     */ import blockbuster.math.molang.MolangParser;
/*     */ import blockbuster.math.molang.expressions.MolangExpression;
/*     */ import com.google.gson.JsonArray;
/*     */ import com.google.gson.JsonElement;
/*     */ import com.google.gson.JsonObject;
/*     */ import javax.vecmath.Matrix4f;
/*     */ import javax.vecmath.Quat4f;
/*     */ import javax.vecmath.Tuple4f;
/*     */ import javax.vecmath.Vector3f;
/*     */ import javax.vecmath.Vector4f;
/*     */ 
/*     */ public class BedrockComponentShapeDisc
/*     */   extends BedrockComponentShapeSphere {
/*  20 */   public MolangExpression[] normal = new MolangExpression[] { MolangParser.ZERO, MolangParser.ONE, MolangParser.ZERO };
/*     */ 
/*     */ 
/*     */   
/*     */   public BedrockComponentBase fromJson(JsonElement elem, MolangParser parser) throws MolangException {
/*  25 */     if (!elem.isJsonObject()) return super.fromJson(elem, parser);
/*     */     
/*  27 */     JsonObject element = elem.getAsJsonObject();
/*     */     
/*  29 */     if (element.has("plane_normal")) {
/*     */       
/*  31 */       JsonElement normal = element.get("plane_normal");
/*     */       
/*  33 */       if (normal.isJsonPrimitive()) {
/*     */         
/*  35 */         String axis = normal.getAsString().toLowerCase();
/*     */         
/*  37 */         if (axis.equals("x"))
/*     */         {
/*  39 */           this.normal[0] = MolangParser.ONE;
/*  40 */           this.normal[1] = MolangParser.ZERO;
/*     */         }
/*  42 */         else if (axis.equals("z"))
/*     */         {
/*  44 */           this.normal[1] = MolangParser.ZERO;
/*  45 */           this.normal[2] = MolangParser.ONE;
/*     */         }
/*     */       
/*     */       } else {
/*     */         
/*  50 */         JsonArray array = element.getAsJsonArray("plane_normal");
/*     */         
/*  52 */         if (array.size() >= 3) {
/*     */           
/*  54 */           this.normal[0] = parser.parseJson(array.get(0));
/*  55 */           this.normal[1] = parser.parseJson(array.get(1));
/*  56 */           this.normal[2] = parser.parseJson(array.get(2));
/*     */         } 
/*     */       } 
/*     */     } 
/*     */     
/*  61 */     return super.fromJson((JsonElement)element, parser);
/*     */   }
/*     */ 
/*     */ 
/*     */   
/*     */   public JsonElement toJson() {
/*  67 */     JsonObject object = (JsonObject)super.toJson();
/*  68 */     JsonArray array = new JsonArray();
/*     */     
/*  70 */     for (MolangExpression expression : this.normal)
/*     */     {
/*  72 */       array.add(expression.toJson());
/*     */     }
/*     */     
/*  75 */     object.add("plane_normal", (JsonElement)array);
/*     */     
/*  77 */     return (JsonElement)object;
/*     */   }
/*     */ 
/*     */ 
/*     */   
/*     */   public void apply(BedrockEmitter emitter, BedrockParticle particle) {
/*  83 */     float centerX = (float)this.offset[0].get();
/*  84 */     float centerY = (float)this.offset[1].get();
/*  85 */     float centerZ = (float)this.offset[2].get();
/*     */     
/*  87 */     Vector3f normal = new Vector3f((float)this.normal[0].get(), (float)this.normal[1].get(), (float)this.normal[2].get());
/*     */     
/*  89 */     normal.normalize();
/*     */     
/*  91 */     Quat4f quaternion = new Quat4f(normal.x, normal.y, normal.z, 1.0F);
/*  92 */     Matrix4f rotation = new Matrix4f();
/*  93 */     rotation.set(quaternion);
/*     */     
/*  95 */     Vector4f position = new Vector4f((float)Math.random() - 0.5F, 0.0F, (float)Math.random() - 0.5F, 0.0F);
/*  96 */     position.normalize();
/*  97 */     rotation.transform((Tuple4f)position);
/*     */     
/*  99 */     position.scale((float)(this.radius.get() * (this.surface ? 1.0D : Math.random())));
/* 100 */     position.add((Tuple4f)new Vector4f(centerX, centerY, centerZ, 0.0F));
/*     */     
/* 102 */     particle.position.x += position.x;
/* 103 */     particle.position.y += position.y;
/* 104 */     particle.position.z += position.z;
/*     */     
/* 106 */     this.direction.applyDirection(particle, centerX, centerY, centerZ);
/*     */   }
/*     */ }


/* Location:              D:\fanbian\[D][龙之核心]DragonCore-2.6.0.3.jar!\blockbuster\components\shape\BedrockComponentShapeDisc.class
 * Java compiler version: 8 (52.0)
 * JD-Core Version:       1.1.3
 */